import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

var router = new Router({
  routes: [{
      path: '/',
      name: 'LoginAndRegister',
      component: resolve => require(['@/views/login'], resolve),
      meta: {
        title: '登录注册',
      },
    },
    {
      path: '/documentType',
      name: 'documentType',
      component: resolve => require(['@/views/SelectSecurityType'], resolve),
      meta: {
        title: '选择账户类型'
      },
    },
    {
      path: '/mainlandCard',
      name: 'mainlandCard',
      component: resolve => require(['@/views/mainlandCard'], resolve),
      meta: {
        title: '上传身份证'//内地
      },
    },
    {
      path: '/CAvideo',
      name: 'CAvideo',
      component: resolve => require(['@/views/CAvideo'], resolve),
      meta: {
        title: 'CA录制视频'
      },
    },
    {
      path: '/autograph',
      name: 'autograph',
      component: resolve => require(['@/views/autograph'], resolve),
      meta: {
        title: '确认签字'
      },
    },
    {
      path: '/examine',
      name: 'examine',
      query:{

      },
      component: resolve => require(['@/views/verification/examine'], resolve),
      meta: {
        title: '审核'
      },
    },
    {
      path: '/verification',
      name: 'verification',
      component: resolve => require(['@/views/verification/index'], resolve),
      meta: {
        title: '核实身份'//第一步
      },
    },
    {
      path: '/custom',
      name: 'custom',
      component: resolve => require(['@/views/custom'], resolve),
      meta: {
        title: '自定义页面'//第一步
      },
    },
    {
      path: '/indexEnd',
      name: 'indexEnd',
      component: resolve => require(['@/views/verification/indexEnd'], resolve),
      meta: {
        title: '查看预约地址'
      },
    },
    {
      path: '/CounterAddress',
      name: 'CounterAddress',
      component: resolve => require(['@/views/verification/CounterAddress'], resolve),
      meta: {
        title: '柜台核实身份'
      },
    },
    {
      path: '/CounterOrder',
      name: 'CounterOrder',
      component: resolve => require(['@/views/verification/CounterOrder'], resolve),
      meta: {
        title: '预约见面'
      },
    },
    {
      path: '/OnlineAddress',
      name: 'OnlineAddress',
      component: resolve => require(['@/views/verification/OnlineAddress'], resolve),
      meta: {
        title: '网上转账'
      },
    },
    {
      path: '/OnlineRemit',
      name: 'OnlineRemit',
      component: resolve => require(['@/views/verification/OnlineRemit'], resolve),
      meta: {
        title: '汇款通知'
      },
    },
    {
      path: '/download',
      name: 'download',
      component: resolve => require(['@/views/download'], resolve),
      meta: {
        title: '下载'
      },
    },
    {
      path: '/errorinfo',
      name: 'Errorinfo',
      component: resolve => require(['@/views/error'], resolve),
      meta: {
        title: '错误页面'
      },
    }
  ]
})

router.beforeEach((to, from, next) => {
  document.title = to.meta.title
  if (to.matched.length === 0) {
    // document.title = to.meta.title //判断此跳转路由的来源路由是否存在，存在的情况跳转到来源路由，否则跳转到404页面
     //匹配前往的路由不存在
    next("/errorinfo");
  } else {
    if(to.path=='/login'){
      sessionStorage.removeItem('token')
    }
    next(); //如果匹配到正确跳转
  }
});
export default router
